# 使用官方 .NET SDK 镜像作为构建环境
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# 复制项目文件
COPY backend/StudentManagement.sln .
COPY backend/StudentManagement.API/StudentManagement.API.csproj StudentManagement.API/
COPY backend/StudentManagement.Application/StudentManagement.Application.csproj StudentManagement.Application/
COPY backend/StudentManagement.Domain/StudentManagement.Domain.csproj StudentManagement.Domain/
COPY backend/StudentManagement.Infrastructure/StudentManagement.Infrastructure.csproj StudentManagement.Infrastructure/

# 还原依赖
RUN dotnet restore

# 复制所有源代码并构建项目
COPY backend/ .
WORKDIR /src/StudentManagement.API
RUN dotnet build -c Release -o /app/build

# 发布项目
FROM build AS publish
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false

# 使用官方 ASP.NET Core 运行时镜像作为运行环境
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

# 从构建阶段复制发布文件
COPY --from=publish /app/publish .

# 设置入口点
ENTRYPOINT ["dotnet", "StudentManagement.API.dll"]